import requests
import json
import os
Data_path = "D:\\film\\videos"
url = 'http://howtodo.yilan.tv/video/v2/head?app=howto_a&guuid=3c2a42ad82d7b5730978dde3ac26bab4&udid=b9d2a5ffc701c501c501c501b15932a3677c11fa8dad3bc57cd3cd01e2bc5feb'
response = requests.get(url)
result = json.loads(response.text)
message = result.get("contents")
list = []
list_1 = []
Name = []
dict = {}
for i in message:
    id = i.get("id")
    name = i.get("video").get("name")
    video_id = "http://howtodo.yilan.tv/video/play?id=" + str(id).strip()
    list.append(video_id)
    Name.append(name)
for k in list:
    res = requests.get(k)
    video_url = json.loads(res.text).get("bitrates")[1].get("uri")
    list_1.append(video_url)
# print(list_1)
for x in range(0,len(list_1)-1):
    dict[Name[x]]=list_1[x]
print(dict)

for x in range(0,len(list_1)-1):
    R = requests.get(list_1[x])
    videos = R.content
    video_name = Name[x]
    file_path = os.path.join(Data_path,"%s.mp4" % (video_name))
    with open(file_path, "wb") as file:
        file.write(videos)

